package com.example.pickupclosefirstdemo.base;

import android.os.Bundle;
import android.util.Log;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.databinding.DataBindingUtil;
import androidx.databinding.ViewDataBinding;

import com.alibaba.android.arouter.launcher.ARouter;
import com.example.pickupclosefirstdemo.util.LogUtil;

public abstract class BaseActivity<V extends ViewDataBinding> extends AppCompatActivity {

    public V binding;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (initContentView(savedInstanceState) != 0) {
            binding = DataBindingUtil.setContentView(this, initContentView(savedInstanceState));
            ARouter.getInstance().inject(this);
            initView();
            initData();
        }else{
            LogUtil.e("LayoutId -->"+ initContentView(savedInstanceState));
        }
    }

    /**
     * 初始化根布局
     *
     * @return 布局layout的id
     */
    public abstract int initContentView(Bundle savedInstanceState);

    //界面销毁，绑定关系销毁
    @Override
    protected void onDestroy() {
        super.onDestroy();
        binding.unbind();
    }

    /**
     * 初始化界面
     */
    public abstract void initView();

    /**
     * 初始化数据
     */
    public abstract void initData();
}
